﻿using System.Collections;

namespace ParaEditor.Infrastructure
{
    public static class Session
    {
        private static Hashtable ht;

        /// <summary>
        /// 存储变量到会话中
        /// </summary>
        /// <param name="sessionName">变量名称key</param>
        /// <param name="sessionValue">变量值value</param>
        public static void SetSession(string sessionName, object sessionValue)
        {
            if (ht == null)
                ht = new Hashtable();
            if (ht.Contains(sessionName.ToString()))
            {
                ht.Remove(sessionName.ToString());
            }
            ht.Add(sessionName.ToString(), sessionValue);
        }

        /// <summary>
        /// 取得会话中变量值
        /// </summary>
        /// <param name="sessionName">变量名称key</param>
        /// <returns></returns>
        public static object GetSession(string sessionName)
        {
            if (ht == null || ht[sessionName.ToString()] == null)
                return "Session Can not Find!";
            return ht[sessionName.ToString()];
        }
    }
}
